package com.acwer.oa.web;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import com.acwer.dao.sys.SysUserDao;
import com.acwer.domain.sys.SysUser;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

@Component
public class CustomUserDetailsService implements UserDetailsService{

	@Autowired
	SysUserDao userDao;
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		QueryWrapper<SysUser> userQuery=new QueryWrapper<SysUser>();
		userQuery.eq("account_id", username);
		userQuery.or().eq("name", username);
		SysUser user=userDao.selectOne(userQuery);
		SecurityUser suser=null;
		if(user!=null){
			suser=new SecurityUser(user);
		}
		
		return suser;
	}

}
